//:C06:ForEach.cpp {-mwcc}
// Use of STL for_each() algorithm.
// {L} Counted
#include <algorithm>
#include <iostream>
#include "Counted.h"
using namespace std;

// Function object:
template<class T> class DeleteT
{
    public: 
        void operator()(T* x)
        {
            delete x;
        }
};

// Template function:
template<class T>
void wipe(T* x)
{
    delete x;
}

int main(void)
{
    CountedVector B("two");
    for_each(B.begin(), B.end(), DeleteT<Counted>());
    CountedVector C("three");
    for_each(C.begin(), C.end(), wipe<Counted>);
}